"""Main application entry point."""
import sys
from .data.loader import DataLoader
from .processing.preprocessor import Preprocessor
from .models.sky_image import SkyImage
from .observation.simulator import ObservationSimulator
from astropy.coordinates import EarthLocation
from astropy.time import Time
import astropy.units as u
import numpy as np


def main():
    """Main function to run the radio simulator."""
    pass


def mock_observation(file_path, telescope_location=None, start_time=None, duration=3600, 
                     telescope_name="default"):
    """
    Execute a mock observation workflow.
    
    Args:
        file_path: Path to sky image file
        telescope_location: EarthLocation object for telescope position (default: Beijing)
        start_time: Time object for observation start time (default: current time)
        duration: Duration of observation in seconds (default: 3600)
        telescope_name: Name of predefined telescope (default: "default")
            Options: "default" (Beijing), "uirapuru"
        
    Returns:
        Array of intensities as a function of time and frequency
    """
    # Load sky image data
    loader = DataLoader()
    raw_data = loader.load_sky_image(file_path)
    
    # Preprocess data with filter
    preprocessor = Preprocessor()
    # Using a simple filter parameter for demonstration
    # In practice, this would be customized based on requirements
    filter_params = {}  # Placeholder for actual filter parameters
    filtered_data = preprocessor.filter_data(raw_data, filter_params)
    
    # Create SkyImage object with filtered data
    sky_image = SkyImage(data=filtered_data)
    
    # Setup telescope location based on name or provided location
    if telescope_location is None:
        if telescope_name == "uirapuru":
            # Uirapuru telescope location
            telescope_location = EarthLocation(
                lat=-7.211637*u.deg, lon=-35.908138*u.deg, height=553*u.m
            )
            # Uirapuru telescope pointing
            elevation = 65.0 * u.deg
            azimuth = 0.0 * u.deg
        else:
            # Default telescope location (Beijing example)
            telescope_location = EarthLocation(
                lat=40.0*u.deg, lon=116.3*u.deg, height=50*u.m
            )
            # Default pointing (zenith)
            elevation = 90.0 * u.deg
            azimuth = 0.0 * u.deg
    else:
        # If location is provided, use default pointing
        elevation = 90.0 * u.deg
        azimuth = 0.0 * u.deg
    
    # Setup default start time if not provided (current time)
    if start_time is None:
        start_time = Time.now()
    
    # Simulate drift scan observation
    simulator = ObservationSimulator()
    observation_result = simulator.simulate_drift_scan(
        sky_image, telescope_location, start_time, duration, azimuth, elevation
    )
    
    return observation_result


if __name__ == "__main__":
    main()